#ifndef _CNODE_H_
#define _CNODE_H_

#include "stdio.h"
#include "windows.h"

#define STRING_LEN_MAX 10
#define LIST_COUNT_MAX 10000

#define IS_NUM(c)	(((c) >= '0') && ((c) <= '9'))
#define IS_CHAR(c)	(((c) >= 'A') && ((c) <= 'Z'))
#define IS_START(c)	((c)=='(')
#define IS_END(c)	((c)==')')

typedef enum {ILL_ITEM, ColorDef, SingleColor, CycleStart, CycleEnd} CItemType;
typedef enum {Empty, Cycle, Color} CNodeType;

class CCycNode;
class CColorNode;
class CColorManager;

/*

*/
class CNode
{
public:
	CCycNode * parentNode;
	CNode * nextNode;
	CNodeType type;
	int singleNum;
	int yarnNum;

public:
	CNode();
	//~CNode();
};

class CColorNode : public CNode
{
public:
	char color;

public:	
	CColorNode(char color, int colorNum);

};


class CCycNode : public CNode
{
public:
	int cycNum;
	int restNum;
	CNode * childList;
	CNode * currentChild;

public:
	CCycNode(int cycNum, int restNum);
	~CCycNode();

	void CalcYarn();
	void AddNode(CNode * newNode);

};


class CColorManager
{
public:
	CCycNode * rootCyc;
	CCycNode * crtCyc;

public:
	CColorManager();
	int GetYarnCount();
	char GetColorByYarnNum(int yarnNum);
	void Init(char uiList[LIST_COUNT_MAX][STRING_LEN_MAX]);

private:
	void AddColorNode(char color, int colorNum);
	void AddCycNode(int cycNum, int restNum);
	CItemType GetType(char * item);
	void GetColorItemInfo(char * item, char &color, int &colorNum);
	void GetCycItemInfo(char * item, int &cycNum, int &restNum);
	int GetStringNum(char * item, int &num);
	CNode * SearchNode(CNode * node, int yarnNum);
};

#endif